Skip to content

Fix CI test flakiness from leaked sys.modules mutations in import-independence property tests#30

Merged
AperturePlus merged 2 commits into
developfrom
copilot/fix-ci-tests-failures
Apr 14, 2026
Merged

Fix CI test flakiness from leaked sys.modules mutations in import-independence property tests#30
AperturePlus merged 2 commits into
developfrom
copilot/fix-ci-tests-failures

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

CI failures were caused by cross-test module identity drift: import-independence property tests cleared aci* entries from sys.modules globally and left later tests comparing objects from different module instances. This manifested as isinstance(...) failures in graph model assertions.

  • Root cause addressed: isolate and restore module cache state

    • Updated get_transitive_imports() in:
      • tests/property/test_http_server_independence_properties.py
      • tests/property/test_mcp_server_independence_properties.py
    • New behavior:
      • Snapshot existing aci* modules
      • Clear aci* modules to measure transitive imports from a clean state
      • Restore original aci* modules in finally to avoid leaking interpreter state
  • Cleanup for readability/maintainability

    • Added _is_aci_module(name: str) -> bool helper in both files to centralize module-name matching logic.
    • Removed duplicated per-test cache-clearing blocks now handled safely inside the shared helper.

Example of the key change pattern:

aci_modules = {k: v for k, v in sys.modules.items() if _is_aci_module(k)}
for mod in aci_modules:
    del sys.modules[mod]

try:
    __import__(module_name)
    return set(sys.modules) - before_import
finally:
    for mod in [k for k in sys.modules if _is_aci_module(k)]:
        del sys.modules[mod]
    sys.modules.update(aci_modules)

@AperturePlus AperturePlus marked this pull request as ready for review April 14, 2026 06:16
@AperturePlus AperturePlus merged commit 15d9778 into develop Apr 14, 2026
1 check passed
@AperturePlus AperturePlus deleted the copilot/fix-ci-tests-failures branch April 24, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants